package com.example.fruitdemo.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.fruitdemo.pojo.Good;
import com.example.fruitdemo.ruslet.MyPage;
import com.example.fruitdemo.ruslet.R;
import com.example.fruitdemo.service.GoodService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/api/fruit")
public class FruitController {
    @Autowired
    GoodService goodService;
    @GetMapping("/list")
    public R<Page> fruitpage(int page,int pageSize,int categoryid,int orderby){
        return goodService.fruitpage(page,pageSize,categoryid,orderby);
    }
    //根据查询名称查询
    @GetMapping("/selectbyname")
    public R<Page> getbyname(String searchname,int page,int orderby){
         return goodService.getbyname(searchname,page,orderby);
    }
    //根据id查询商品信息
    @GetMapping("/getone")
    public R<Good> getone(Long id){
        Good good = goodService.getById(id);
        if(good==null) return R.Err("查询失败");
        else return R.Ok(good);
    }
    //查询新品
    @GetMapping("/newgoods")
    public R<List<Good>> getnewgoods(){
        return goodService.getnewgoods();
    }
    //放入最近浏览记录中
    @PostMapping("/presentlook")
    public R<String> presentlook(@RequestBody Map<String,Object> params){
        String authorization = params.get("authorization").toString();
        String goodid = params.get("goodid").toString();
        return goodService.presentlook(authorization,goodid);
    }
    //获取最近浏览记录
    @GetMapping("/getpresent")
    public R<Page> getprsent(String authorization){
        return goodService.getPresent(authorization);
    }
}
